// Agent basis
/* agent perceives an area that is a square with the size N with
   the agent in the center. Each agent is able to see N*N cells. */

/* Initial beliefs and rules */
/* BELIEFS */


/* RULES */



/* initial DESIRES */
!search.

/* INTENTIONS (PLANS AND ACTIONS) */

+!search : not pos(_,_,_)
<- .print("I am alive. I dont know my pos");
.wait("+pos(_,_,_)");
.print("I know my pos");
!search.

+!search : pos(_,_,_)
<- !move;
-pos(_,_,_);
!search.

+!search : pos(_,_,_) & cow(_,Cx,Cy)
<- +target(Cx,Cy); 
!move. 

+!move : pos(X,Y,_) & target(Cx,Cy) & Cx \== X & Cy \== Y
<- .print("move to target");
br.poli.ecomp.sma.massim.action.FindPos( X, Y, Cx, Cy, NewX,NewY );
br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
moveTo(Direction);
!move.

+!move : pos(X,Y,_) & target(Cx,Cy) & Cx == X & Cy == Y
<- .print("I am at target");
-target(Cx,Cy).

+!move : pos(X,Y,_)
<- .print("Selecting a new position randomly...");
br.poli.ecomp.sma.massim.action.FindPos(X,Y,X-20,Y,NewX,NewY);
//br.poli.ecomp.sma.massim.action.RandomPos(X,Y,NewX,NewY);
.print("Discovering the new position direction...");
br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
moveTo(Direction). 